package com.nondo.rdp.finance.repository.setting.advert;

import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.nondo.rdp.core.common.StatusConstant;
import com.nondo.rdp.finance.domain.setting.advert.Advert;

public interface AdvertRepository extends JpaRepository<Advert, Long>, JpaSpecificationExecutor<Advert> {
    @Query("select a from Advert a where a.id=:id and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
    Optional<Advert> findOne(@Param("id") int id);

    @Modifying
    @Query("update Advert set delFlag='" + StatusConstant.DEL_FLAG_DELETE + "' where id = ?1")
    void deleteById(Long id);

    Advert save(Advert advert);

    @Query("select a from Advert a where a.type=:type and a.isShow=1 and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "' order by sort desc")
	List<Advert> findAll(@Param("type") Integer type);

}
